﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CsharpTrainer.Domain.Services;
using CsharpTrainer.Core.JSON;
using Zeus.Thunder.Core;
using Zeus.Thunder.Core;

namespace SharpTrainer.Other
{
    class GtaJsonAnalyzeTest : ITestCase
    {
        public void Run()
        {
            string url = "http://182.50.114.49:7080/fare/FareQuery.html?journey=OW&org1=PEK&dst1=SEA&outDate1=2012-04-13&fareCurrCode=CNY&currentUserDistId=40288081360a03e901360a0a56bc003f&sign=ABA869FF393705FFD82DD41E9452117D";

            string jsonResult = "";
            try
            {
                GtaService service = new GtaService(url);
                jsonResult = service.FareQuery();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Get GTA Service Exception: " + ex.ToString());

                return;
            }

            string tab = "  ";
            string sep = "-----------------------------------------------------------------";
            string tab2 = "    ";
            string sep2 = "***************************************";

            JsonObject newObj = new JsonObject(jsonResult);
            Console.Write("stat: ");
            Console.WriteLine(newObj["stat"].Value);
            Console.WriteLine("fareList: ");
            for (int i = 0; i < newObj["fareList"].Items.Count; i++)
            {
                Console.Write(tab + "fareDetailUUID: ");
                Console.WriteLine(newObj["fareList"].Items[i].Object["fareDetailUUID"].Value);
                Console.Write(tab + "fareId: ");
                Console.WriteLine(newObj["fareList"].Items[i].Object["fareId"].Value);
                Console.Write(tab + "ruleId: ");
                Console.WriteLine(newObj["fareList"].Items[i].Object["ruleId"].Value);
                Console.Write(tab + "fareAirline: ");
                Console.WriteLine(newObj["fareList"].Items[i].Object["fareAirline"].Value);
                Console.Write(tab + "fareAirlineNameCn: ");
                Console.WriteLine(newObj["fareList"].Items[i].Object["fareAirlineNameCn"].Value);
                Console.Write(tab + "amount_adt: ");
                Console.WriteLine(newObj["fareList"].Items[i].Object["amount_adt"].Value);
                Console.Write(tab + "tax_adt: ");
                Console.WriteLine(newObj["fareList"].Items[i].Object["tax_adt"].Value);
                
                //route
                Console.WriteLine(tab + "route: ");
                Console.WriteLine(tab2 + sep2);
                for (int j = 0; j < newObj["fareList"].Items[i].Object["route"].Items.Count; j++)
                {
                    Console.Write(tab2 + "depdate: ");
                    Console.WriteLine(newObj["fareList"].Items[i].Object["route"].Items[j].Object["depdate"].Value);
                    Console.Write(tab2 + "arrdate: ");
                    Console.WriteLine(newObj["fareList"].Items[i].Object["route"].Items[j].Object["arrdate"].Value);
                    Console.Write(tab2 + "outairport: ");
                    Console.WriteLine(newObj["fareList"].Items[i].Object["route"].Items[j].Object["outairport"].Value);
                    Console.Write(tab2 + "outcity: ");
                    Console.WriteLine(newObj["fareList"].Items[i].Object["route"].Items[j].Object["outcity"].Value);
                    Console.Write(tab2 + "outairportNameCn: ");
                    Console.WriteLine(newObj["fareList"].Items[i].Object["route"].Items[j].Object["outairportNameCn"].Value);
                    Console.Write(tab2 + "outcityNameCn: ");
                    Console.WriteLine(newObj["fareList"].Items[i].Object["route"].Items[j].Object["outcityNameCn"].Value);
                    Console.Write(tab2 + "inairport: ");
                    Console.WriteLine(newObj["fareList"].Items[i].Object["route"].Items[j].Object["inairport"].Value);
                    Console.Write(tab2 + "incity: ");
                    Console.WriteLine(newObj["fareList"].Items[i].Object["route"].Items[j].Object["incity"].Value);
                    Console.Write(tab2 + "inairportNameCn: ");
                    Console.WriteLine(newObj["fareList"].Items[i].Object["route"].Items[j].Object["inairportNameCn"].Value);
                    Console.Write(tab2 + "incityNameCn: ");
                    Console.WriteLine(newObj["fareList"].Items[i].Object["route"].Items[j].Object["incityNameCn"].Value);
                    Console.Write(tab2 + "airline: ");
                    Console.WriteLine(newObj["fareList"].Items[i].Object["route"].Items[j].Object["airline"].Value);
                    Console.Write(tab2 + "airlineNameCn: ");
                    Console.WriteLine(newObj["fareList"].Items[i].Object["route"].Items[j].Object["airlineNameCn"].Value);
                    Console.Write(tab2 + "flightno: ");
                    Console.WriteLine(newObj["fareList"].Items[i].Object["route"].Items[j].Object["flightno"].Value);
                    Console.Write(tab2 + "cabin: ");
                    Console.WriteLine(newObj["fareList"].Items[i].Object["route"].Items[j].Object["cabin"].Value);
                    Console.Write(tab2 + "planeStyle: ");
                    Console.WriteLine(newObj["fareList"].Items[i].Object["route"].Items[j].Object["planeStyle"].Value);
                    Console.WriteLine(tab2 + sep2);
                }

                Console.WriteLine(sep);
            }
        }
    }
}
